package com.wthink.newMain.settings.menuManager

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.wthink.hzgj.R
import com.wthink.hzgj.databinding.FragmentMenuManagerBinding
import com.wthink.newMain.settings.menuManager.inner.MenuManagerLineFragment
import com.wthink.newMain.settings.menuManager.inner.MenuManagerSystemFragment

class MenuManagerFragment :Fragment(){
    private val viewModel by viewModels<MenuManagerViewmodel>()

    private lateinit var binding: FragmentMenuManagerBinding

    var menuManagerLineFragment : MenuManagerLineFragment? = null
    var menuManagerSystemFragment : MenuManagerSystemFragment? = null

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(
            inflater,
            R.layout.fragment_menu_manager,
            container,
            false
        )
        binding.viewModel = viewModel
        binding.lifecycleOwner = this
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        menuManagerLineFragment = MenuManagerLineFragment()
        menuManagerSystemFragment = MenuManagerSystemFragment()

        activity!!.supportFragmentManager
            .beginTransaction()
            .add(R.id.menu_manager_content, menuManagerLineFragment!!)
            .commit()

        binding.lineSettings.isSelected = true

        binding.lineSettings.setOnClickListener {
            addFragment(menuManagerLineFragment!!)
            binding.systemSettings.isSelected = false
            binding.lineSettings.isSelected = true
        }

        binding.systemSettings.setOnClickListener {
            addFragment(menuManagerSystemFragment!!)
            binding.systemSettings.isSelected = true
            binding.lineSettings.isSelected = false
        }
    }

    private fun addFragment(fragment: Fragment) {
        activity!!.supportFragmentManager
            .beginTransaction()
            //.setCustomAnimations(R.anim.design_bottom_sheet_slide_in, R.anim.design_bottom_sheet_slide_out)
            .replace(R.id.menu_manager_content, fragment, fragment.javaClass.simpleName)
            .commit()
    }
}